//
//  SchemeDetail.m
//  cutter
//
//  Created by mac on 16/1/5.
//  Copyright © 2016年 e360. All rights reserved.
//
#import "SpaceViewController.h"
#import "MatchCenterCtrl.h"
#import "SchemeSelector.h"

//
@implementation SchemeTabBarView
@end
@implementation SchemeSelector
- (void)viewDidLoad{
    [super viewDidLoad];
    if (self.tabBarView) {
        [self.view addSubview:self.tabBarView];
        [self selectedTouch:self.tabBarView.spaceView];
        [self.widthLayout setConstant:self.view.bounds.size.width];
    }
}
//
-(UITabBar *)tabBar{
    UITabBar *temp = [super tabBar];
    [temp setFrame:CGRectZero];
    [temp setHidden:YES];
    return temp;
}
-(UINavigationController *)moreNavigationController{
    UINavigationController *ctrl = [super moreNavigationController];
    if (ctrl) {
        [ctrl.navigationController setNavigationBarHidden:YES];
        [ctrl setNavigationBarHidden:YES];
    }
    return ctrl;
}
//
- (IBAction)exitTouch:(id)sender{
    if (self.onSelected) {
        self.onSelected(self, nil);
    }else{
        if (self.navigationController) {
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    }
}
-(void)setSelectedIndex:(NSUInteger)selectedIndex{
    //搭配
    id item = [self.viewControllers objectAtIndex:selectedIndex];
    if ([item isKindOfClass:MatchCenterCtrl.class]) {
        MatchCenterCtrl *ctrl = item;
        [ctrl.condition setValue:@(self.classids) forKey:@"spaceid"];
        [ctrl setOnSelected:self.onSelected];
        [ctrl setIsshare:selectedIndex == 1];
        [ctrl setType:1];
    }
    if ([item isKindOfClass:SpaceViewController.class]) {
        SpaceViewController *ctrl = item;
        ctrl.classids = self.classids;
        [ctrl setOnSelected:self.onSelected];
        [ctrl setType:1];
    }
    [super setSelectedIndex:selectedIndex];
}
- (IBAction)selectedTouch:(UIButton *)sender {
    if (self.tabBarView) {
        NSArray *items = [NSArray arrayWithObjects:self.tabBarView.spaceView, self.tabBarView.MatchView, self.tabBarView.myMatchView, nil];
        for (uint i = 0; i < items.count; i++){
            UIButton *btn = [items objectAtIndex:i];
            if (btn == sender) {
                [self setSelectedIndex:i];
                [btn setSelected:YES];
            }else{
                [btn setSelected:NO];
            }
        }
    }
}
@end